// 封装获取频道列表的逻辑
import {useEffect, useState} from "react";
import {getChannelsAPI} from "@/apis/article";

function useChannel() {
    // 获取频道列表的所有逻辑
// 频道数据
    const [channelList, setChannelList] = useState([]);
    useEffect(() => {
        // 调用api的函数
        const getChannels = async () => {
            const res = await getChannelsAPI();
            setChannelList(res.data.channels)
        }
        // 调用函数
        getChannels()
    }, [])
    // 把组件要用到的数据return出去
    return {channelList}
}

export {useChannel}